package org.nanquan.dotjava.validator;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.validator.Field;
import org.apache.commons.validator.GenericValidator;
import org.apache.commons.validator.Validator;
import org.apache.commons.validator.ValidatorAction;
import org.apache.commons.validator.util.ValidatorUtils;
import org.apache.struts.action.ActionMessages;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.Resources;



@SuppressWarnings("serial")
public class CheckField extends FieldChecks {
	
//	void Test()
//	{
//		Field field=new Field();
//		field.
//	}
	
	
	public static boolean validateMinLength
	(Object object, ValidatorAction validatoraction, Field field,
	 ActionMessages actionmessages, Validator validator,
	 HttpServletRequest httpservletrequest) {
	@SuppressWarnings("unused")
	Object object_43_ = null;
	String string;
	if (isString(object))
	    string = (String) object;
	else
	    string
		= ValidatorUtils.getValueAsString(object, field.getProperty());
	if (!GenericValidator.isBlankOrNull(string)) {
	    try {
	    	
		int i;
		if(field.getVarValue("minlength")!=null)
		i= Integer.parseInt(field.getVarValue("minlength"));
		else
			i=Integer.parseInt(field.getArg(1).toString());
		if (!GenericValidator.minLength(string, i)) {
		    actionmessages.add
			(field.getKey(),
			 Resources.getActionMessage(validator,
						    httpservletrequest,
						    validatoraction, field));
		    return false;
		}
	    } catch (Exception exception) {
		actionmessages.add
		    (field.getKey(),
		     Resources.getActionMessage(validator, httpservletrequest,
						validatoraction, field));
		return false;
	    }
	}
	return true;
    }

}
